//
//  MainViewController.m
//  haolaDoc
//
//  Created by chen on 2017/5/12.
//  Copyright © 2017年 deyi. All rights reserved.
//

#import "MainViewController.h"
#import "AppMonitor.h"
#import "SDCycleScrollView.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _mainScrollView.contentSize = CGSizeMake(0,self.view.frame.size.height);
    //加载滚动图
    [AppMonitor getScrollViewPictures];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loadScrollImages:) name:@"loadScrollImages" object:nil];
    //远程门诊点击事件
    [_remoteClinicImageView setUserInteractionEnabled:YES];
    UITapGestureRecognizer *remoteClinicImageViewTab=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onRemoteClinicImageViewClick:)];
    [_remoteClinicImageView addGestureRecognizer:remoteClinicImageViewTab];
    //日程安排点击事件
    [_scheduleImageView setUserInteractionEnabled:YES];
    UITapGestureRecognizer *scheduleImageViewTab=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onscheduleImageViewClick:)];
    [_scheduleImageView addGestureRecognizer:scheduleImageViewTab];
}
//加载滚动视图图片
-(void)loadScrollImages:(NSNotification *)notification{
    NSData *scrollData = [notification.userInfo objectForKey:@"data"];
    _scrollViewImagesDic=[NSJSONSerialization  JSONObjectWithData:scrollData options:0 error:nil];
    NSArray *imagesURLStrings = [self getArrayByKey:@"imgUrl"];
    NSArray *titles =[self getArrayByKey:@"title"];
    SDCycleScrollView *banner2 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, self.menuView.frame.origin.y) delegate:nil placeholderImage:nil];
    banner2.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
    banner2.imageURLStringsGroup = imagesURLStrings;
    banner2.titlesGroup = titles;
    banner2.delegate=self;
    banner2.currentPageDotColor = [UIColor colorWithRed:0 green:0.57 blue:0.89 alpha:100];
    [self.mainScrollView addSubview:banner2];
}

/**
 *  通过键值获取滑动视图的数据中的数组
 *
 *  @param key 键值
 *
 *  @return 数组
 */
-(NSArray *)getArrayByKey:(NSString *)key{
    NSMutableArray *tempArray = [[NSMutableArray alloc]initWithCapacity:_scrollViewImagesDic.count];
    for (int index = 0; index<_scrollViewImagesDic.count; index++) {
        [tempArray addObject:[_scrollViewImagesDic[index] objectForKey:key]];
    }
    return tempArray;
}

-(void)onRemoteClinicImageViewClick:(id)sender {
    [self performSegueWithIdentifier:@"showConsultation" sender:sender];

}
-(void)onscheduleImageViewClick:(id)sender {
    [self performSegueWithIdentifier:@"showSchedule" sender:sender];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
